@extends('admin_system/public/layout')
@section('content')
<div class="col-xs-12">
    {{--成员列表--}}
    <div>
        <iframe src="{{asset('admin_system/member/select_member_list?companyId='.$companyId)}}" frameborder="0" style="width:100%;min-width:500px;height:85vh;"></iframe>
    </div>

    {{--已选中--}}
    <div class="selected">
        <h4>已选用户</h4>
        <form class="form-inline">

            <div class="form-group" id="members">
              {{--  <div class="input-group">
                    <input type="text" class="form-control" READONLY>
                    <div class="input-group-addon">X</div>
                </div>--}}
            </div>
        </form>
    </div>

    {{--确定按钮--}}

    <div class="text-center">
        <button class="btn btn-danger btn-lg" onclick="return_data()">确&nbsp;&nbsp;&nbsp;定</button>
    </div>

</div>




<script>
    /*
    * 显示选中的成员
    * */
    function show_selected_member(members){

        var content = "";
        for(var member of members){
            content += '<div class="input-group">'+
                            '<input type="text" class="form-control" READONLY value="' + member.name + '">'+
                            '<div class="input-group-addon pointer" onclick="delete_member(' + member.id + ')">X</div>'+
                        '</div>';
        }
        document.getElementById('members').innerHTML = content;
    }

    var members = new Array();


    /**
    * 删除会员
    * */
    function delete_member(id){
        var member = '';
        for(var key in members){
            member = members[key];
            if(member.id == id){
                members.splice(key,1);
                break;
            }
        }
        show_selected_member(members);
    }


    /*
    * 添加会员
    * */
    function add_member(member){
        members.push(member);
        show_selected_member(members);
    }
    show_selected_member(members);


    //返回数据
    function return_data(){
        var callback = GET('callback');
            window.parent[callback](members);
    }

    //获取GET变量
    function GET(name) {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }



</script>

